<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <link rel="stylesheet" href="bootstrap.min.css">
    <script src="https://cdn.staticfile.org/jquery/2.1.1/jquery.min.js"></script>
    <script src="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>
    <link rel="stylesheet" href="bootstrap-table.min.css">
    <script src="ry-ui.js"></script>
    <script src="bootstrap-table.min.js"></script>
    <script src="bootstrap-table-tree.js"></script>
    <link href="ry-ui.css">
</head>

<body>
    <div class="col-sm-12 select-table table-striped">
        <table id="bootstrap-tree-table"></table>
    </div>

    <script>
        var addFlag = "";
        var editFlag = "";
        var removeFlag = "";
        var datas = "";
        var prefix = "/system/dept"

        $(function() {
            var options = {
                code: "deptId",
                parentCode: "parentId",
                uniqueId: "deptId",
                data: [
                    {
                        "parentId": 0,
                        "deptName": "空天防御数据中心",
                        "deptId":1,
                        "leader":"张三"
                    },
                    {
                        "parentId": 1,
                        "deptName": "空天防御数据中心1",
                        "deptId":2,
                        "leader":"张三"
                    },
                    {
                        "parentId": 1,
                        "deptName": "空天防御数据中心2",
                        "deptId":3,
                        "leader":"张三"
                    },
                    {
                        "parentId": 0,
                        "deptName": "空天防御数据中心",
                        "deptId":4,
                        "leader":"张三"
                    },
                ],
                createUrl: prefix + "/add/{id}",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove/{id}",
                modalName: "部门",
                columns: [
                    {
                        field: 'selectItem',
                        radio: true
                    },
                    {
                        field: 'deptName',
                        title: '部门名称',
                        align: "left"
                    },
                    {
                        field: 'leader',
                        title: '负责人',
                        align: "left"
                    },
                    {
                        title: '操作',
                        align: 'right',
                        formatter: function(value, row, index) {
                            if (row.parentId != 0) {
                                var actions = [];
                                actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.deptId + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                                actions.push('<a class="btn btn-info  btn-xs ' + addFlag + '" href="javascript:void(0)" onclick="$.operate.add(\'' + row.deptId + '\')"><i class="fa fa-plus"></i>新增</a> ');
                                actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.deptId + '\')"><i class="fa fa-trash"></i>删除</a>');
                                return actions.join('');
                            } else {
                                return "";
                            }
                        }
                    }
                ]
            };
            $.treeTable.init(options);
        });
    </script>

</body>
</html>